package com.boolib.commons.util;

import com.boolib.commons.Const;
import com.boolib.commons.entity.ServerResponse;
import com.boolib.pojo.ShopBrand;
import org.apache.logging.log4j.util.Strings;

public class ServerResponseUtil {


    private  ServerResponseUtil(){}


    public  static ServerResponse argumentCheck(Object... objects){


        for (Object obj :objects){

            if(obj instanceof  String ){
                if(Strings.isBlank(obj.toString()))
                    return argumentNUll();
            }


            if(obj == null )
                return argumentNUll();

        }

        return ServerResponse.createBySuccess();

    }

    public static ServerResponse  argumentNUll(){
        return  ServerResponse.createByError(Const.System.Status.ARGUMENTNULL.getCode(),Const.System.Status.ARGUMENTNULL.getMessage());
    }

    public static ServerResponse resultCheck(Object result,Class clazz) {

        if(clazz.cast(result) == null )return ServerResponse.createByError(Const.System.Status.UNEXIST.getCode(),
                Const.System.Status.UNEXIST.getMessage());
       return ServerResponse.createBySuccess(clazz.cast(result));


    }

    public static ServerResponse updateSuccess(String txt) {
        return ServerResponse.createBySuccessMessage(txt);
    }

    public static ServerResponse updateFail(String txt) {
        return ServerResponse.createBySuccessMessage(txt);
    }

    public static ServerResponse insertSuccess(String txt)  {
        return ServerResponse.createBySuccessMessage(txt);
    }

    public static ServerResponse insertFail(String txt)  {
        return ServerResponse.createByErrorMessage(txt);
    }

    public static ServerResponse NotExist(String txt)  {
        return ServerResponse.createByError(Const.System.Status.UNEXIST.getCode(),txt);
    }


    public static ServerResponse ISEXIST(String txt) {
        return ServerResponse.createByError(Const.System.Status.EXIST.getCode(),txt);
    }


}
